package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 查询分类
     * @param categoryPageQueryDTO
     * @return
     */
    Page<Category> findCategoryByNameAndType(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 插入分类数据
     * @param category
     */
    void insertCategory(Category category);

    /**
     * 根据id查询分类
     * @param id
     * @return
     */
    @Update("update category set status = #{status} where id = #{id}")
    void updateStatus(Integer status, Long id);

    /**
     * 删除分类
     * @param categoryId
     */
    @Delete("delete from category where id = #{categoryId}")
    void delete(Long categoryId);

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @Select("select * from category where type = #{type}")
    List<Category> findCategoryByType(Integer type);

    /**
     * 修改分类
     *
     * @param category
     */
    void update(Category category);

    /**
     * 根据id查询分类
     * @param categoryId
     * @return
     */
    @Select("select * from category where id = #{categoryId}")
    Category findCategoryByCategoryId(Long categoryId);

    /**
     * 根据id查询分类名称
     * @param categoryId
     * @return
     */
    @Select("select name from category where id = #{categoryId}")
    String findCategoryNameByCategoryId(Long categoryId);


    List<Category> findCategorysByType(Integer type);
}
